/**
 * @file   LoanAuthService.java
 * @date   2012-11-21下午11:59:25
 * @author User
 */
package com.gzceb.zhgjj.service;

import com.gzceb.zhgjj.web.dao.LoanAuthDAO;
import com.gzceb.zhgjj.web.entity.LoanAuth;

/**
 * <p>贷款授权服务层类。</p>
 *
 * @date   2012-11-21下午11:59:25 
 * @author liqing
 * @description 
 */
public class LoanAuthService {
	private LoanAuthDAO loanAuthDAO;

	public LoanAuthService(){
		
	}
	
	public LoanAuthDAO getLoanAuthDAO() {
		return loanAuthDAO;
	}

	public void setLoanAuthDAO(LoanAuthDAO loanAuthDAO) {
		this.loanAuthDAO = loanAuthDAO;
	}
	
	/**
	 * 判断是否申请已经存在于数据库中
	 * @param contCode String
	 * @return boolean
	 * 
	 */
	public boolean isExist(String contCode){
		LoanAuth loanAuth = new LoanAuth();
		loanAuth = loanAuthDAO.findByContCode(contCode);
		if (null == loanAuth || !(loanAuth instanceof LoanAuth)){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * 保存贷款授权信息到贷款授权表中
	 */
	public boolean saveToDB(LoanAuth loanAuth){
		boolean isSuc = true;
		if(null != loanAuthDAO.findByContCode(loanAuth.getContcode())){
			// 如果不为空，则说明记录中已存在此条授权信息
			isSuc = false;
		}else{
			try{
				loanAuthDAO.save(loanAuth);
			} catch (Exception e){
				isSuc = false;
			}	
		}
		
		return isSuc;
	}
	
	/**
	 * 根据中心识别码判断审批的授权状态，查info_loanaprv表authorStat 字段
	 * @param contCode String
	 * @return boolean
	 */
	public boolean isAuthed(String contCode){
		LoanAuth loanAuth = new LoanAuth();
		loanAuth = loanAuthDAO.findByContCode(contCode);
		if( null == loanAuth ||"0".equals(loanAuth.getIsrevoked()) 
				|| "2".equals(loanAuth.getIsrevoked())){
			//如果审批表里没记录 或者 审批表对应记录是未授权或已撤销授权，则反馈 未授权
			return false;
		}
		return true;
	}

}
